comments = {}
commands = {"Check", "Plead", "Challenge", "Fake Attack"}
randomdialogue = {"[next]"}

defensemisstext = ""
sprite = "empty"
name = "Undyne The Undying"
hp = 23000
def = 99999
atk = 5
check = ""
dialogbubble = "rightwide"
canspare = false
cancheck = false

SetActive(false)

function HandleAttack(attackstatus)
    if attackstatus == -1 then
		if Encounter["StatusPhase3"][3] == "Fake Attack" then
			for i=1,3 do
				Audio.PlaySound("healsound")
			end
			Encounter["Undyne"]["Timer"] = 0
			Encounter["Undyne"]["Animation"] = "Hurt"
		else
			Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Miss Undyne"
		end
    else
		Encounter["Undyne"]["Timer"] = 0
		Encounter["Undyne"]["Animation"] = "Hurt"
		Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Fight Undyne"
    end
end

function BeforeDamageCalculation()
	SetDamage(1)
end

function HandleCustomCommand(command)
	if command == "CHECK" then
		BattleDialog({"[effect:none]UNDYNE THE UNDYING 99ATK 99DEF[w:10]\nThe heroine that NEVER gives up."})
		if string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 5, 5) == "0" then
			SetAlMightyGlobal("ProgresoProgresivamenteProgresante1", string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 1, 4).."1"..string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 6))
			if GetAlMightyGlobal("ProgresoProgresivamenteProgresante1") == "111111" then
				SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 8).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 10))
				Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 9}
			end
		end
		Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Check Undyne"
	elseif command == "CHECAR" then
		BattleDialog({"[effect:none]UNDYNE THE UNDYING 99ATK 99DEF[w:10]\nLa heroína que NUNCA se rinde."})
		if string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 5, 5) == "0" then
			SetAlMightyGlobal("ProgresoProgresivamenteProgresante1", string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 1, 4).."1"..string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 6))
			if GetAlMightyGlobal("ProgresoProgresivamenteProgresante1") == "111111" then
				SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 8).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 10))
				Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 9}
			end
		end
		Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Check Undyne"
	elseif command == "PLEAD" then
		BattleDialog({"[effect:none]You tell Undyne you don't want\rto fight anymore.[w:10][func:Laugh]\nUndyne just laughs at you."})
		Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Plead"
	elseif command == "SUPLICAR" then
		BattleDialog({"[effect:none]Le dices a Undyne que ya no\rquieres pelear.[w:10][func:Laugh]\nUndyne solo se ríe de ti."})
		Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Plead"
	elseif command == "CHALLENGE" then
		Encounter.Call("SetHeadUndyne", "Mean Look")
		BattleDialog({"[effect:none]You tell Undyne that if she\rcouldn't kill you once.", "[effect:none][func:SetHeadUndyne,Hurt]What makes her think she will\rsucceed this time?", "[effect:none]Undyne got angry.[w:10]\nThe bullets get faster!"})
		Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Challenge"
	elseif command == "RETAR" then
		Encounter.Call("SetHeadUndyne", "Mean Look")
		BattleDialog({"[effect:none]Le dices a Undyne que si ella\rno pudó matarte una sola vez.", "[effect:none][func:SetHeadUndyne,Hurt]Qué le hace pensar que tendrá\réxito esta vez?", "[effect:none]Undyne se enojó.[w:10]\nLos misiles se vuelven rápidos!"})
		Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Challenge"
	elseif command == "FAKE ATTACK" or command == "ATAQUE FALSO" then
		Encounter["nextwaves"] = {"Fake Attack"}
		State("DEFENDING")
		Encounter["StatusPhase3"][Encounter["progress"] + 1] = "Fake Attack"
	end
end

function SetHeadUndyne(sprite)
	Encounter.Call("SetHeadUndyne", sprite)
end

function Laugh()
	Encounter.Call("Laugh")
end